package com.asiainfo.ssm.execute.dao.impl;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.lang.StringUtils;

import com.asiainfo.ssm.execute.bo.BOChannelAccessParamEngine;
import com.asiainfo.ssm.execute.dao.interfaces.IChannelAccessParamDAO;
import com.asiainfo.ssm.execute.ivalues.IBOChannelAccessParamValue;


public class ChannelAccessParamDAOImpl implements IChannelAccessParamDAO {

	/*
	 * (non-Javadoc)
	 * @see com.asiainfo.ssm.execute.dao.interfaces.IChannelAccessParamDAO#search(java.lang.String, java.lang.String, java.lang.String)
	 */
	public IBOChannelAccessParamValue[] queryChanelAccessParam(String actId, String channelId,String criticalPointId, String messageCount,
			String etWorkCount,int state) throws Exception {
		// TODO Auto-generated method stub
		StringBuffer sqlCond = new StringBuffer();
        Map paraMap = new HashMap();
        sqlCond.append("1=1");
        if(!StringUtils.isEmpty(actId)){
        	sqlCond.append(" AND ").append(IBOChannelAccessParamValue.S_ActId).append(" =:actId ");
        	paraMap.put("actId",actId);
        }
        if(!StringUtils.isEmpty(channelId)){
        	sqlCond.append(" AND ").append(IBOChannelAccessParamValue.S_ChannelId).append(" =:channelId ");
        	paraMap.put("channelId", channelId);
        }

        if(!StringUtils.isEmpty(criticalPointId)){
        	sqlCond.append(" AND ").append(IBOChannelAccessParamValue.S_CriticalPointId).append(" =:criticalPointId ");
        	paraMap.put("criticalPointId",criticalPointId);
        }
        if(!StringUtils.isEmpty(messageCount)){
        	sqlCond.append(" AND ").append(IBOChannelAccessParamValue.S_MessageCount).append(" =:messageCount ");
        	paraMap.put("messageCount", messageCount);
        }
        if(!StringUtils.isEmpty(etWorkCount)){
        	sqlCond.append(" AND ").append(IBOChannelAccessParamValue.S_NetworkCount).append(" =:etWorkCount ");
        	paraMap.put("etWorkCount", etWorkCount);
        }
        if(state>0){
        	sqlCond.append(" AND ").append(IBOChannelAccessParamValue.S_State).append(" =:state ");
        	paraMap.put("state", state);
        }
		return BOChannelAccessParamEngine.getBeans(sqlCond.toString(), paraMap);
	}

	public IBOChannelAccessParamValue[] queryChanelAccessParam(String condition, Map parameter) throws Exception {
		return BOChannelAccessParamEngine.getBeans(condition, parameter);
	}

	@Override
	public void saveChannelAccessParam(IBOChannelAccessParamValue value) throws Exception {
		  if(value.isNew()){
			  value.setParamId(BOChannelAccessParamEngine.getNewId().longValue());
		  }
		  BOChannelAccessParamEngine.save(value);
	}

	@Override
	public IBOChannelAccessParamValue getChannelAccessParamById(long paramId) throws Exception { 
		return BOChannelAccessParamEngine.getBean(paramId);
	}


}
